﻿using System;
using System.Globalization;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NMortgage.UI.Converters;

namespace NMortgage.UI.Tests.Converters
{
    public enum ResourcesEnum
    {
        WithResource,
        WithoutResource,
    }
    [TestClass]
    public class EnumToResourceConverterTest
    {
        private EnumToResourceConverter Subject { get; set; }
        [TestInitialize]
        public void Initialize()
        {
            Subject = new EnumToResourceConverter();
        }

        [TestMethod]
        public void Returns_Null_If_Object_Is_Not_Enum()
        {
            // Arrange
            // Act
            var actual = Subject.Convert("hi", null, Properties.Resources.ResourceManager, null);
            // Assert
            Assert.IsNull(actual);
        }
        [TestMethod]
        public void Returns_Null_If_ResourceManager_Is_Null()
        {
            // Arrange
            // Act
            var actual = Subject.Convert(ResourcesEnum.WithoutResource, null, null, null);
            // Assert
            Assert.IsNull(actual);
        }
        [TestMethod]
        public void Reads_Resource_String_From_Resources_By_Convention()
        {
            // Arrange
            var expected = Properties.Resources.ResourcesEnum_WithResource;
            // Act
            var actual = Subject.Convert(ResourcesEnum.WithResource, null, Properties.Resources.ResourceManager,
                                         CultureInfo.CurrentCulture);
            // Assert
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void Returns_Enum_ToString_If_Resource_Key_Is_Not_Found()
        {
            // Arrange
            var expected = ResourcesEnum.WithoutResource.ToString();
            // Act
            var actual = Subject.Convert(ResourcesEnum.WithoutResource, null, Properties.Resources.ResourceManager,
                                         CultureInfo.CurrentCulture);
            // Assert
            Assert.AreEqual(expected, actual);
        }
       
        [TestMethod]
        public void Returns_Null_When_Value_Is_Null()
        {
            // Arrange
            // Act
            var actual = Subject.Convert(null, null, null, CultureInfo.CurrentCulture);
            // Assert
            Assert.IsNull(actual);
        }
        [TestMethod]
        public void ConvertBack_Is_Not_Supported()
        {
            // Arrange
            var expected = DependencyProperty.UnsetValue;
            // Act
            var actual = Subject.ConvertBack("anything", null, null, null);
            // Assert
            Assert.AreEqual(expected, actual);
        }
   
    }
}
